package com.stylefeng.guns.wx.modular.scheduled.util.webmagic;/**
 * Package: com.stylefeng.guns.webmagic
 * Description： TODO
 * Author: 4967677099@qq.com
 * Date: Created in 2018/3/18 0018 16:35
 * Version: 0.0.1
 * Modified By: 4967677099@qq.com
 */

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 496767099@qq.com
 * @create 2018-03-18 16:35
 **/
public class WebmagicQiDianUtil implements PageProcessor {

    private Site site = Site.me().setDomain("book.qidian.com");

    /**
     * key: 爬虫地址
     * vaule:书名
     */
    public static Map<String,Map<String,String>> maps = new HashMap<>();

    @Override
    public void process(Page page) {
        String url = page.getUrl().toString();
        String title = page.getHtml().xpath("//div[@class='book-info ']/h1/em/text()").toString();
        String latestChapter = page.getHtml().xpath("//li[@class='update']/div[@class='detail']/p[@class='cf']/a/text()").toString();
        page.putField("title", title);
        page.putField("latestChapter", latestChapter);
        Map<String,String> map = new HashMap<>();
        map.put("title",title);
        map.put("latestChapter",latestChapter);
        maps.put(url,map);
    }

    @Override
    public Site getSite() {
        return site;
    }
}